<template>
  <div>
    <a-carousel arrows autoplay>
      <div slot="prevArrow" class="custom-slick-arrow" style="left: 10px;zIndex: 1">
        <a-icon type="left-circle" />
      </div>
      <div slot="nextArrow" class="custom-slick-arrow" style="right: 10px">
        <a-icon type="right-circle" />
      </div>
      <div>
        <router-link :to="'/movies/mid/' + 1">
          <img src="http://127.0.0.1:8081/images/1/picture.jpg" style="width: 100%; height: 100%" />
        </router-link>
      </div>
      <div>
        <router-link :to="'/movies/mid/' + 2021">
          <img
            src="http://127.0.0.1:8081/images/2021/picture.jpg"
            style="width: 100%; height: 100%"
          />
        </router-link>
      </div>
      <div>
        <router-link :to="'/movies/mid/' + 2334">
          <img
            src="http://127.0.0.1:8081/images/2334/picture.jpg"
            style="width: 100%; height: 100%"
          />
        </router-link>
      </div>
      <div>
        <router-link :to="'/movies/mid/' + 1150">
          <img
            src="http://127.0.0.1:8081/images/1150/picture.jpg"
            style="width: 100%; height: 100%"
          />
        </router-link>
      </div>
    </a-carousel>

    <a-row style="margin-top: 30px;">
      <div>
        <h1 style="font-size: 2rem; display: inline;" id="month">
          <a-icon type="fire" />&emsp;新上映
        </h1>
        <h2 style="display: inline-block;">
          <a-icon type="sync" @click="switchNew" :spin="isSpinNew" />&emsp;换一批
        </h2>
      </div>
    </a-row>
    <a-spin size="large" :spinning="loadingN">
      <div class="ant-pro-pages-list-projects-cardList">
        <a-list :data-source="NewMovie" :grid="{ gutter: 24, xl: 4, lg: 3, md: 3, sm: 2, xs: 1 }">
          <a-list-item slot="renderItem" slot-scope="item">
            <router-link :to="'/movies/mid/' + item.mid">
              <a-card class="ant-pro-pages-list-projects-card" hoverable>
                <img
                  slot="cover"
                  :src="'http://127.0.0.1:8081/images/' + item.mid + '/picture.jpg'"
                  :alt="item.name"
                />
                <a-card-meta :title="item.name">
                  <template slot="description">
                    <p>语言：{{ item.language }} / {{ item.shoot }}</p>
                    <p>导演：{{ item.directors }}</p>
                    <p>时长：{{ item.timelong }}</p>
                    <p>评分：{{ item.score + 5 }}</p>
                  </template>
                </a-card-meta>
                <div>
                  <span>{{ item.issue | fromNow }}</span>
                </div>
              </a-card>
            </router-link>
          </a-list-item>
        </a-list>
      </div>
    </a-spin>

    <a-row style="margin-top: 30px;">
      <h1 style="font-size: 2rem; display: inline;" id="month">
        <a-icon type="fire" />&emsp;热门推荐
      </h1>
      <h2 style="display: inline-block;">
        <a-icon type="sync" @click="switchHot" :spin="isSpinHot" />&emsp;换一批
      </h2>
    </a-row>
    <a-spin size="large" :spinning="loading">
      <div class="ant-pro-pages-list-projects-cardList">
        <a-list :data-source="HotData" :grid="{ gutter: 24, xl: 4, lg: 3, md: 3, sm: 2, xs: 1 }">
          <a-list-item slot="renderItem" slot-scope="item">
            <router-link :to="'/movies/mid/' + item.mid">
              <a-card class="ant-pro-pages-list-projects-card" hoverable>
                <img
                  slot="cover"
                  :src="'http://127.0.0.1:8081/images/' + item.mid + '/picture.jpg'"
                  :alt="item.name"
                />
                <a-card-meta :title="item.name">
                  <template slot="description">
                    <p>语言：{{ item.language }} / {{ item.shoot }}</p>
                    <p>导演：{{ item.directors }}</p>
                    <p>时长：{{ item.timelong }}</p>
                    <p>评分：{{ item.score + 5 }}</p>
                  </template>
                </a-card-meta>
                <div class="cardItemContent">
                  <span>{{ item.issue | fromNow }}</span>
                </div>
              </a-card>
            </router-link>
          </a-list-item>
        </a-list>
      </div>
    </a-spin>
  </div>
</template>
<script>
import moment from "moment";
import { getNewMovieList, getHotMovieList } from "@/api/MovieRest";
export default {
  data() {
    return {
      HotData: [],
      NewMovie: [],
      loading: true,
      loadingN: true,
      isSpinHot: false,
      isSpinNew: false,
    };
  },
  filters: {
    fromNow(date) {
      return moment(date).fromNow();
    },
  },
  created() {
    this.getHot();
    this.getNew();
  },
  methods: {
    getHot() {
      getHotMovieList({ num: 4 }).then((res) => {
        this.loading = false;
        this.HotData = res;
        if (this.isSpinHot) this.isSpinHot = !this.isSpinHot;
      });
    },
    getNew() {
      getNewMovieList({ num: 4 }).then((res) => {
        this.loadingN = false;
        this.NewMovie = res;
        if (this.isSpinNew) this.isSpinNew = !this.isSpinNew;
      });
    },

    switchHot() {
      this.isSpinHot = !this.isSpinHot;
      this.getHot();
    },
    switchNew() {
      this.isSpinNew = !this.isSpinNew;
      this.getNew();
    },
  },
};
</script>
<style scoped>
/* For demo */
.ant-carousel >>> .slick-slide {
  text-align: center;
  height: 360px;
  line-height: 360px;
  background: #364d79;
  overflow: hidden;
}

.ant-carousel >>> .custom-slick-arrow {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  opacity: 0.3;
}
.ant-carousel >>> .custom-slick-arrow:before {
  display: none;
}
.ant-carousel >>> .custom-slick-arrow:hover {
  opacity: 0.5;
}

.ant-carousel >>> .slick-slide h3 {
  color: #fff;
}
</style>
